<?php
namespace app\wechat\controller;
use think\View;

class Message extends Common
{
    // 用户消息首页
    public function index()
    {
        $param['member_role'] = 'partner';
        $param['member_id'] = session('member_id');
        $param['terrace'] = 'weixin';
        $data = call_interface('get_msg_unread_count', $param);
        //dump($data);
        $this->assign('data', $data['data']);

        return view();
    }

    // 消息列表
    public function msg_list() {
        $msg_type = input('param.msg_type', 0);
        if (request()->isAjax()) {
            $param['member_role'] = 'partner';
            $param['member_id'] = session('member_id');
            $param['terrace'] = 'weixin';
            $param['msg_type'] = $msg_type;
            $data = call_interface('get_msg_list', $param);
            if ($data['code'] == 200) {
                $view = new View();
                $view->assign('data', $data['data']['data']);
                $tpl = $view->fetch('message/msg_list_tpl');
                $data['tpl'] = $tpl;
            }
            return json($data);
        } else {
            $this->assign('msg_type', $msg_type);
            return view();
        }
    }

    // 消息详情
    public function msg_info() {
        $id = input('param.id');
        $param = [
            'member_id' =>session('member_id'),
            'msg_id' => $id
        ];
        $data = call_interface('get_msg_info', $param);
        //dump($data);
        $this->assign('data', $data['data']);
        return view();
    }
}
